<?php

class AskControl extends Control {

    public function index() {
        switch ($_GET['where']) {
            case 0:
                $sql = 'SELECT * FROM hd_ask';
                $sql2 = 'SELECT count(*) as c FROM hd_ask';
                break;
            case 1:
                $sql = 'SELECT * FROM hd_ask where solve=0';
                $sql2 = 'SELECT count(*) as c FROM hd_ask where solve=0';
                break;
            case 2:
                $sql = 'SELECT * FROM hd_ask where solve=1';
                $sql2 = 'SELECT count(*) as c FROM hd_ask where solve=1';
                break;
            case 3:
                $sql = 'SELECT * FROM hd_ask where answer=0';
                $sql2 = 'SELECT count(*) as c FROM hd_ask where answer=0';
                break;
            default:
                $sql = 'SELECT * FROM hd_ask';
                $sql2 = 'SELECT count(*) as c FROM hd_ask';
                break;
        }
        $data = M('ask')->query($sql);
        $this->assign('ask', $data);
        $data2 = M('ask')->query($sql2);
        $this->assign('askcount', $data2[0]);
        $this->display();
    }

    public function del() {
        $asid = (int) $_GET['asid'];
        if (M('ask')->exec('DELETE FROM hd_ask where asid=' . $asid)) {
            $this->error('删除成功！');
        } else {
            $this->error('删除失败！');
        }
    }

}
